package com.example.demo.common;

import com.example.demo.pojo.Warehouse;
import com.example.demo.service.Position;
import com.example.demo.util.CalculateDistance;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class OnlyMath {



    public String random(){
        String time= String.valueOf(System.currentTimeMillis());
        int random= (int)(Math.random()*100000);
        String ran=String.valueOf(random);
        String math=time+random;
        return math;
    }

    public String lastChar(String string){
        String[] format=string.split("\\.");
        int b=format.length;
        return format[b-1];
    }

    //获取仓库位置
    public int warehouse( List<Warehouse>list,double jing,double wei){
       Iterator<Warehouse> iterator =list.iterator();
       //获取第一个仓库
       long jingdu=Long.valueOf(list.get(0).getX());
       long weidu=Long.valueOf(list.get(0).getY());
       double decide=CalculateDistance.getDistance(jing,wei,jingdu,weidu);
       int  repertory=list.get(0).getRepertoryid();
       //从第二个开始和第一个比较他们之间的距离
       if(list.size()>1){
          for (int a=1;a<list.size();a++){
              long decidejing=Long.valueOf(list.get(a).getX());
              long decidewei= Long.valueOf(list.get(a).getY());
              double decidejuli=CalculateDistance.getDistance(jing,wei,decidejing,decidewei);
              if(decidejuli<decide){
                  decide=decidejuli;
                  repertory=list.get(a).getRepertoryid();
              }
          }
      }
        return  repertory;
    }


}
